﻿using System;
using RxjhServer.DbClss;

namespace RxjhServer
{
	public class BOSS地图
	{
		private int _ID;

		private int _MIP_ID;

		private string _MAP_NAME;

		private int _BOSS_ID;

		private string _BOSS_NAME;

		private int _DROP_ID;

		private string _DROP_NAME;

		private int _TIMER;

		private int _X;

		private int _Y;

		private bool _bcanmove;

		public int ID
		{
			get
			{
				return this._ID;
			}
			set
			{
				this._ID = value;
			}
		}

		public int 地图ID
		{
			get
			{
				return this._MIP_ID;
			}
			set
			{
				this._MIP_ID = value;
			}
		}

		public string 地图名字
		{
			get
			{
				return this._MAP_NAME;
			}
			set
			{
				this._MAP_NAME = value;
			}
		}

		public int 怪物ID
		{
			get
			{
				return this._BOSS_ID;
			}
			set
			{
				this._BOSS_ID = value;
			}
		}

		public string 怪物名字
		{
			get
			{
				return this._BOSS_NAME;
			}
			set
			{
				this._BOSS_NAME = value;
			}
		}

		public int 携带物品ID
		{
			get
			{
				return this._DROP_ID;
			}
			set
			{
				this._DROP_ID = value;
			}
		}

		public string 携带物品名字
		{
			get
			{
				return this._DROP_NAME;
			}
			set
			{
				this._DROP_NAME = value;
			}
		}

		public int 出现时间
		{
			get
			{
				return this._TIMER;
			}
			set
			{
				this._TIMER = value;
			}
		}

		public int 坐标X
		{
			get
			{
				return this._X;
			}
			set
			{
				this._X = value;
			}
		}

		public int 坐标Y
		{
			get
			{
				return this._Y;
			}
			set
			{
				this._Y = value;
			}
		}

		public bool 是否可以进入
		{
			get
			{
				return this._bcanmove;
			}
			set
			{
				this._bcanmove = value;
			}
		}

		public static bool boss地图是否开启(string mapName)
		{
			bool result = false;
			try
			{
				if (World.BOSS设置list.Count == 0)
				{
					return result;
				}
				foreach (BOSS地图 current in World.BOSS设置list.Values)
				{
					if (mapName == current.地图名字 && current.是否可以进入)
					{
						result = true;
						break;
					}
				}
			}
			catch (Exception arg)
			{
				Form1.WriteLine(0, "boss地图是否开启 错误" + arg);
			}
			return result;
		}

		public static bool cheekBossMap(int nMapID)
		{
			bool result = false;
			try
			{
				if (World.BOSS设置list.Count == 0)
				{
					return result;
				}
				foreach (BOSS地图 current in World.BOSS设置list.Values)
				{
					if (nMapID == current.地图ID)
					{
						result = true;
						break;
					}
				}
			}
			catch (Exception arg)
			{
				Form1.WriteLine(0, "cheekBossMap 错误" + arg);
			}
			return result;
		}

		public static void resetBossInfo()
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					foreach (BOSS地图 current in World.BOSS设置list.Values)
					{
						if (current.是否可以进入)
						{
							World.AddNpc(current.怪物ID, (float)current.坐标X, (float)current.坐标Y, current.地图ID);
						}
						current.是否可以进入 = false;
					}
				}
			}
			catch (Exception arg)
			{
				Form1.WriteLine(0, "resetBossInfo 错误" + arg);
			}
		}

		private static void moveOutBossMap()
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					foreach (Players current in World.allConnectedChars.Values)
					{
						if (BOSS地图.cheekBossMap(current.人物坐标_地图))
						{
							current.移动(529f, 1528f, 15f, 101);
						}
					}
					foreach (BOSS地图 current2 in World.BOSS设置list.Values)
					{
						World.delNpc(current2.地图ID, current2.怪物ID);
					}
				}
			}
			catch (Exception arg)
			{
				Form1.WriteLine(0, "resetBossInfo 错误" + arg);
			}
		}

		public static void chaeckBossInfo(int thisHour)
		{
			try
			{
				if (World.BOSS设置list.Count != 0)
				{
					BOSS地图.moveOutBossMap();
					foreach (BOSS地图 current in World.BOSS设置list.Values)
					{
						if (current.出现时间 == thisHour)
						{
							current.是否可以进入 = true;
							World.发送公告(string.Concat(new string[]
							{
								current.地图名字,
								"将在10分钟后刷新boss[",
								current.怪物名字,
								"]请在10分钟内使用命令[@BOSS ",
								current.地图名字,
								"]进入"
							}));
						}
					}
				}
			}
			catch (Exception arg)
			{
				Form1.WriteLine(0, "chaeckBossInfo 错误" + arg);
			}
		}

		public static void 更新BOSS次数()
		{
			try
			{
				RxjhClass.初始化BOSS次数();
				foreach (Players current in World.allConnectedChars.Values)
				{
					if (current.检查金符())
					{
						current.BOSS次数 = 1;
					}
					else
					{
						current.BOSS次数 = 0;
					}
				}
			}
			catch (Exception)
			{
			}
		}

		public static DropClass 获得BOSS持有物品(int nMapID, int npcID)
		{
			try
			{
				foreach (BOSS地图 current in World.BOSS设置list.Values)
				{
					if (nMapID == current.地图ID && npcID == current.怪物ID)
					{
						return new DropClass
						{
							FLD_NAME = current.携带物品名字,
							FLD_PID = current.携带物品ID
						};
					}
				}
			}
			catch (Exception)
			{
			}
			return null;
		}
	}
}
